define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'scanwork/customer/index' + location.search,
                    add_url: 'scanwork/customer/add',
                    edit_url: 'scanwork/customer/edit',
                    del_url: 'scanwork/customer/del',
                    multi_url: 'scanwork/customer/multi',
                    import_url: 'scanwork/customer/import',
                    export_url: 'scanwork/customer/export',
                    table: 'customer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'customer_code', title: __('客户编码'), operate: 'LIKE'},
                        {field: 'customer_name', title: __('客户名称'), operate: 'LIKE'},
                        {field: 'contact_person', title: __('联系人'), operate: 'LIKE'},
                        {field: 'contact_phone', title: __('联系电话'), operate: 'LIKE'},
                        {field: 'contact_email', title: __('联系邮箱'), operate: 'LIKE'},
                        {field: 'special_requirements', title: __('特殊要求'), operate: 'LIKE', formatter: function(value, row, index) {
                            if (value && value.length > 50) {
                                return value.substring(0, 50) + '...';
                            }
                            return value || '';
                        }},
                        {field: 'status', title: __('状态'), searchList: {"1":__('正常'),"0":__('隐藏')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('操作'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        import: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
